/**
 * LeftAndMain_left.js
 * Code for supporting the left-hand panel of all the 2-pane admin windows
 * This includes code for the action panel at the top, and the draggable, ajax-linked tree.
 */
 
if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
SiteTreeHandlers.parentChanged_url = 'admin/ajaxupdateparent';
SiteTreeHandlers.orderChanged_url = 'admin/ajaxupdatesort';
SiteTreeHandlers.showRecord_url = 'admin/show/';
SiteTreeHandlers.controller_url = 'admin';

var _HANDLER_FORMS = {
	addpage : 'Form_AddPageOptionsForm',
	batchactions : 'batchactionsforms',
	search : 'search_options'
};



function fixHeight_left() {
	$('left').style.height = $('right').style.height;
}


/**
 * Reorganise action checkbox 
 */
ReorganiseAction = Class.create();
ReorganiseAction.applyTo('#sortitems');
ReorganiseAction.prototype = {
	initialize: function () {
		this.isDraggable = false;
	},
	
	onclick : function() {
		if (this.isDraggable == false) {
			$('sitetree').makeDraggable();
			this.isDraggable = true;
		} else {
			$('sitetree').stopBeingDraggable();
			this.isDraggable = false;
		}
	}
}

/**
 * Control the site tree filter
 */
SiteTreeFilterForm = Class.create();
SiteTreeFilterForm.applyTo('form#search_options');
SiteTreeFilterForm.prototype = {
	onsubmit: function() {
			$('SiteTreeSearchButton').className = 'loading';
			Ajax.SubmitForm(this, null, {
				onSuccess :  function(response) {
					$('SiteTreeIsFiltered').value = 1;
					$('SiteTreeSearchButton').className = '';
					$('sitetree_ul').innerHTML = response.responseText;
					Behaviour.apply();
					statusMessage('Filtered tree','good');
				},
				onFailure : function(response) {
					errorMessage('Could not filter site tree<br />' + response.responseText);
				}
			});
		
		return false;
	}
}